package com.project.controller;

import com.project.bean.StatisticsMonthBean;
import com.project.bean.StatisticsProductBean;
import com.project.service.IStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "统计控制器")
@RequestMapping("statistics")
public class StatisticsController {
    @Autowired
    private IStatisticsService statisticsService;
    @ApiOperation("按商品统计销售额")
    @ApiImplicitParams({
            @ApiImplicitParam(name="startDate",value = "起始日期"),
            @ApiImplicitParam(name="endDate",value = "结束日期")
    })
    @RequestMapping("statisticsByProduct")
    @RequiresPermissions("count:product")
    public Map<String, List<StatisticsProductBean>> statisticsByProduct(LocalDate startDate, LocalDate endDate) {
        return statisticsService.statisticsByProduct(startDate, endDate);
    }

    @ApiOperation("按月份统计销售额")
    @ApiImplicitParam(name="year",value = "年份")
    @RequestMapping("statisticsByMonth")
    @RequiresPermissions("count:month")
    public List<StatisticsMonthBean> statisticsByMonth(String year){
        return statisticsService.statisticsByMonth(year);
    }
    @ApiOperation("获取所有年份")
    @RequestMapping("getYears")
    @RequiresPermissions("count:month")
    public List<String> getYears(){
        return statisticsService.getYears();
    }
}
